//
//  FFLogFileFormatter.m
//  FFSurveillance
//
//  Created by roro_latrobe on 16/10/31.
//  Copyright © 2016年 cn.wanda. All rights reserved.
//

#import "FFLogFileFormatter.h"
#import "FFLogManager.h"
#import "FFLogFilter.h"

@implementation FFLogFileFormatter

//此处需要保证线程安全!
- (NSString *)formatLogMessage:(DDLogMessage *)logMessage{
    if (![FFLogManager sharedManager].logConfig.isWriteLogIntoFile) {//不写入文件则返回空
        return nil;
    }
    if(!logMessage.message)
        return @"";
    NSString *text = [self logByAddInfo:logMessage];
    return text;
}

- (NSString *)logByAddInfo:(DDLogMessage *)logMessage{
    NSMutableString *finalLog = [NSMutableString string];
    
    [finalLog appendFormat:@"%@ ", [logMessage timestamp]];
    
    if (![[logMessage queueLabel] isEqualToString:@"thread:com.apple.main-thread"]) {
        [finalLog appendFormat:@"thread:%@ ", logMessage->_queueLabel];
    }
    
    [finalLog appendFormat:@"file:%@ ", [logMessage fileName]];
    
    [finalLog appendFormat:@"method:%@ ", [logMessage function]];
    
    [finalLog appendFormat:@"line:%lu ", (unsigned long)[logMessage line]];
    
    [finalLog appendString:logMessage->_message];
    


    
    return finalLog;
}

@end
